package com.qujia.station.controller;


import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.core.page.PageDomain;
import com.qujia.common.core.page.TableDataInfo;
import com.qujia.common.core.page.TableSupport;
import com.qujia.common.utils.StringUtils;
import com.qujia.common.utils.sql.SqlUtil;
import com.qujia.station.domain.CommodityManagement;
import com.qujia.station.service.CommodityManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (CommodityManagement)表控制层
 *
 * @author makejava
 * @since 2023-08-16 11:26:42
 */
@RestController
@RequestMapping("/commodityManagement")
@Api("非油品商品管理接口")
public class CommodityManagementController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private CommodityManagementService commodityManagementService;

    /**
     * 分页查询
     *
     * @param commodityManagement 筛选条件
     * @return 查询结果
     */
    @PostMapping("/list")
    @ApiOperation("分页查询")
    public TableDataInfo queryByPage(@RequestBody CommodityManagement commodityManagement) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
            commodityManagement.setPageNum(pageNum);
            commodityManagement.setPageSize(pageSize);
            commodityManagement.setOrderBy(orderBy);
        }
        List<CommodityManagement> list=commodityManagementService.query(commodityManagement);
        return getDataTable(list);
    }
    /**
     * 查询统计数量
     *
     * @param commodityManagement 筛选条件
     * @return 查询结果 statisticsData
     */
    @PostMapping("/getStatisticsData")
    @ApiOperation("查询统计数量")
    public AjaxResult getStatisticsData(@RequestBody CommodityManagement commodityManagement) {
        Map<String, String> statisticsData = commodityManagementService.getStatisticsData(commodityManagement);
        return AjaxResult.success(statisticsData);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/queryById/{id}")
    @ApiOperation("通过主键查询单条数据")
    public AjaxResult queryById(@PathVariable("id") Long id) {
        return AjaxResult.success(this.commodityManagementService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param commodityManagement 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation("新增数据")
    public AjaxResult add(@RequestBody CommodityManagement commodityManagement) {
        return AjaxResult.success(this.commodityManagementService.insert(commodityManagement));
    }

    /**
     * 编辑数据
     *
     * @param commodityManagement 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    @ApiOperation("编辑数据")
    public AjaxResult edit(@RequestBody CommodityManagement commodityManagement) {
        return AjaxResult.success(this.commodityManagementService.update(commodityManagement));
    }

    /**
     * 删除数据
     *
     * @param ids 主键
     * @return 删除是否成功
     */
    @PostMapping("/delete")
    @ApiOperation("删除数据")
    public AjaxResult delete(@RequestBody List<Long> ids) {
        return AjaxResult.success(this.commodityManagementService.delete(ids));
    }

}

